package com.TripMate.system.service.impl;

import com.TripMate.system.common.ErrorCode;
import com.TripMate.system.exception.BusinessException;
import com.TripMate.system.mapper.TripsMapper;
import com.TripMate.system.model.dto.trips.TripsQueryRequest;
import com.TripMate.system.model.entity.Trips;
import com.TripMate.system.model.vo.FavoritesByTripVO;
import com.TripMate.system.model.vo.TripsVO;
import com.TripMate.system.service.TripsService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author dongmianyan
* @description 针对表【trips(行程表)】的数据库操作Service实现
* @createDate 2024-11-28 16:13:53
*/
@Service
public class TripsServiceImpl extends ServiceImpl<TripsMapper, Trips>
    implements TripsService {

    @Resource
    private TripsMapper tripsMapper;

    @Override
    public Page<TripsVO> getQueryByAll(Page<TripsVO> pageParam, TripsQueryRequest tripsQueryRequest) {
        // 自定义分页查询
        List<TripsVO> tripsVOS = tripsMapper.getQueryByAll(pageParam, tripsQueryRequest);
        if (tripsVOS != null) {
            pageParam.setRecords(tripsVOS);
            return pageParam;
        } else {
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "查询失败");
        }
    }

    @Override
    public Page<TripsVO> getQueryByMy(Page<TripsVO> pageParam, TripsQueryRequest tripsQueryRequest, Long userId) {
        // 自定义分页查询
        List<TripsVO> tripsVOS = tripsMapper.getQueryByMy(pageParam, tripsQueryRequest, userId);
        if (tripsVOS != null) {
            pageParam.setRecords(tripsVOS);
            return pageParam;
        } else {
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "查询失败");
        }

    }

    @Override
    public TripsVO getQueryById(Integer id) {
        TripsVO tripsVOS = tripsMapper.getQueryById(id);
        if (tripsVOS != null) {
            return tripsVOS;
        } else {
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "查询失败");
        }
    }

    @Override
    public Page<TripsVO> getlistByAll(Page<TripsVO> pageParam, TripsQueryRequest tripsQueryRequest) {
        // 自定义分页查询
        List<TripsVO> tripsVOS = tripsMapper.getlistByAll(pageParam, tripsQueryRequest);
        if (tripsVOS != null) {
            pageParam.setRecords(tripsVOS);
            return pageParam;
        } else {
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "查询失败");
        }
    }
}




